require(['./config'], () => {
    require(['header','footer','cookie'], () => {
        class login {
            constructor() {
              this.logins()
            } 
      // logins
      logins() {
        $('#buttonlog').on('click', function () {
          let username = $('#textLogin').val()
          let password = $('#pw').val()
          let Mpassword = $('#twoPw').val()
          let data = localStorage.getItem('data')
          console.log(data)
          if (username && password && Mpassword) {
            if (password == Mpassword) {
              data  = JSON.parse(data)
              let isData  = data.some(name => {
                return name.username == username && name.password == password
              })   
               console.log(isData)
              if(isData == false){
                alert('你输入的用户名没有？')
                if(confirm('是否要跳转注册页注册')){
                  window.location.href = '/html/registe.html'
                }
              }else if(isData == true){
                alert('登录成功即将返回主页')
                $.cookie('dataname',username)
                $.cookie('dataname', username, { expires: 7, path: '/' });


                window.location.href = '/'
              }

            } else {
              alert('输入的密码不相同')
              $('#textLogin').val('')
              $('#pw').val('')
              $('#twoPw').val('')
            }
          } else {
            alert('请输入所有值')
          }

        })
      }
    }
    new login()
    })
     
})